Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(auth): add default workspace support for user handling #9099

Merged
merged 3 commits into from
Dec 17, 2024

Conversation

AMoreaux
Copy link
Contributor

@AMoreaux AMoreaux commented Dec 17, 2024

Introduce defaultWorkspaceId to improve workspace redirection logic. Updated GraphQL schema, server logic, and frontend components accordingly to prioritize default workspaces when available.

Summary

This PR adds a mechanism to handle and prioritize default workspace selection for users during authentication. It updates the logic in multiple components and services to ensure users are redirected to their default workspaces if no specific selection is provided.

Main changes:

  • GraphQL Schema Updates:

    • Enhanced UserExists GraphQL entity with a new defaultWorkspaceId field to specify the user's default workspace.
    • Updated queries and mutations to handle the defaultWorkspaceId.
  • Client-Side Updates:

    • Enhanced useAuth hook to include logic for managing default workspace redirection.
    • Adjusted UI logic in SignInUpGlobalScopeForm to utilize the defaultWorkspaceId.
  • Server-Side Adjustments:

    • Modified AuthService to include defaultWorkspaceId in checkUserExists.
    • Default workspace logic added to the backend flow for consistent handling.
  • Tests/Helpers:

    • Added utility and type changes to integrate the new backend response changes (e.g., UserExists GraphQL).
  • Subsequent function lifecycle was adjusted to include recheck for workspace token states when performing sign-in flows.

Introduce `defaultWorkspaceId` to improve workspace redirection logic. Updated GraphQL schema, server logic, and frontend components accordingly to prioritize default workspaces when available.
@AMoreaux AMoreaux self-assigned this Dec 17, 2024
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

This PR adds default workspace support to improve user redirection during authentication, with the main change being the introduction of a defaultWorkspaceId field in the UserExists response.

  • Added defaultWorkspaceId field in /packages/twenty-front/src/modules/auth/graphql/queries/checkUserExists.ts for workspace prioritization
  • Updated workspace redirection logic in /packages/twenty-front/src/modules/auth/sign-in-up/components/SignInUpGlobalScopeForm.tsx to prioritize default workspace
  • Fixed duplicate state setting in /packages/twenty-front/src/modules/auth/hooks/useAuth.ts clearSession function
  • Added explicit workspace domain cookie clearing in session management
  • Updated handleVerify to use defaultWorkspace instead of previous selection logic

7 file(s) reviewed, 3 comment(s)
Edit PR Review Bot Settings | Greptile

packages/twenty-front/src/modules/auth/hooks/useAuth.ts Outdated Show resolved Hide resolved
Comment on lines +10 to +11
@Field(() => String)
defaultWorkspaceId: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider making defaultWorkspaceId optional since a user might not have a default workspace set

Eliminates redundant setting of `domainConfigurationState` in the `useAuth` hook. This prevents unnecessary operations and ensures cleaner state management.
Refactored the data handling logic for the checkUserExists response to improve readability and maintainability. The changes streamline variable usage and eliminate redundant nesting. Functionality remains unchanged, ensuring proper redirection or mode-switching behavior.
@charlesBochet charlesBochet merged commit 07bde48 into main Dec 17, 2024
22 checks passed
@charlesBochet charlesBochet deleted the feat/redirect-on-default-workspace branch December 17, 2024 18:56
Copy link

Thanks @AMoreaux for your contribution!
This marks your 29th PR on the repo. You're top 2% of all our contributors 🎉
See contributor page - Share on LinkedIn - Share on Twitter

Contributions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants